﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Kimd.Motion
{
    public class SingleAxisGoHomeStep : Step
    {
        public string AxisName { get; set; }
        public SingleAxisGoHomeStep()
        {

        }
        public SingleAxisGoHomeStep(string description, StepType stepType)
            : base(description, stepType)
        {

        }
        public override void Prepare(Dictionary<string, Axis> machineAxis, Dictionary<string, Cylinder> machineCylinder, Tray tray = null, int trayIndex = -1, int nozzleIndex = -1)
        {
            machineAxis[AxisName].SetSpeed(SpeedType.Manual);
            base.Prepare(machineAxis, machineCylinder);
        }
        public override bool Run(Dictionary<string, Axis> machineAxis, Dictionary<string, Cylinder> machineCylinder, Dictionary<string, Sensor> machineSensor, out string errInfo)
        {
            errInfo = "";
            if (!machineAxis[AxisName].GoHome((short)machineAxis[AxisName].HomeMode, machineAxis[AxisName].HomeDirP))
            {
                errInfo = "回零失败!";
                return false;
            }
            return true;
        }
        public override TreeNode ToTreeNode()
        {
            TreeNode node = new TreeNode();
            node.Text = this.ToString();
            node.Tag = this;
            return node;
        }
        public override void Stop(Dictionary<string, Axis> machineAxis)
        {
            machineAxis[AxisName].StopMovement = true;
        }
        public override string ToString()
        {
            return $"{this.Description}-[{AxisName}回零]";
        }
    }
}
